package com.jucai.pppeiyouclient.view.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import com.jucai.pppeiyouclient.MainActivity;
import com.jucai.pppeiyouclient.R;
import com.jucai.pppeiyouclient.utils.ActivityCollector;
import com.jucai.pppeiyouclient.utils.LogUtils;
import com.jucai.pppeiyouclient.utils.LoginUtils;

import io.rong.imkit.RongIM;
import io.rong.imlib.RongIMClient;

/**
 * Created by UPC on 2017/5/5.
 */

public class ChatTest extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chat_test);
        ((TextView) findViewById(R.id.common_title_text)).setText("融云集成测试");

        String token = LoginUtils.getRongyun_token(this);
        LogUtils.e("onCreate:" + token);
        RongIM.connect(token, new RongIMClient.ConnectCallback() {
            @Override
            public void onTokenIncorrect() {
                LogUtils.e("onTokenIncorrect");
            }

            @Override
            public void onSuccess(String userId) {
                LogUtils.e("onSuccess:" + userId);
            }

            @Override
            public void onError(RongIMClient.ErrorCode errorCode) {
                LogUtils.e("onError:" + errorCode.getMessage());
            }
        });
        findViewById(R.id.common_back).setOnClickListener(this);
        findViewById(R.id.common_home_back).setOnClickListener(this);
    }

    public void conversationList(View view) {
        if (RongIM.getInstance() != null)
            RongIM.getInstance().startConversationList(this);
    }

    public void conversation(View view) {
        if (RongIM.getInstance() != null)
            RongIM.getInstance().startPrivateChat(this, "对方的uid", "对方的昵称");
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.common_back:
                ActivityCollector.removeActivity(this);
                break;

            case R.id.common_home_back:
                startActivity(new Intent(ChatTest.this, MainActivity.class));
                ActivityCollector.removeActivity(this);
                break;
        }
    }

}
